package com.sdtw.bookshop.shop.mapper;

import com.sdtw.bookshop.shop.bean.BookInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface BookMapper {

    @Select("select * from bookinfo where bookState=1")
    List<BookInfo> findAll();

    @Insert("insert into bookinfo values(null,#{bookName},#{bookAuthor},#{bookPublisher},#{bookSheet},#{bookkaiben},#{bookPages},#{bookEdition},#{isbn},#{wordCount},#{paperback},#{price},#{myPrice},#{category},#{classId},#{synopsis},#{recommended},#{bookList},#{bigImg},#{smallImg},1)")
    void addBook(BookInfo bookInfo);

    @Update("update bookinfo set bookName=#{bookName},bookAuthor=#{bookAuthor},bookPublisher=#{bookPublisher},bookSheet=#{bookSheet},bookkaiben#{bookkaiben},bookkaiben=#{bookkaiben},bookPages=#{bookPages},bookEdition=#{bookEdition},isbn=#{isbn},wordCount=#{wordCount},paperback=#{paperback},price=#{price},myPrice=#{myPrice},category=#{category},classId=#{classId},synopsis=#{synopsis},recommended=#{recommended},bookList=#{bookList} where id=#{id})")
    void updateBookInfo(Integer id);

    @Select("select * from bookinfo where id = #{id} and bookState=1")
    BookInfo findByBookId(int id);
    @Update("update bookinfo set bookState = 0 where id = #{id}")
    void deleteBookInfo(int id);


}
